PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Reference Expressions

References are compound names that refer to objects in applications, the system, or AppleScript. Because each object has a value, a reference can be used to represent a value in a script. A reference expression is a reference that AppleScript interprets as a value.

A reference can function as a reference to an object or as a reference expression. When a reference is the direct parameter of a command, it usually functions as a reference to an object, indicating to which object the command should be sent. In most other cases, a reference functions as an expression that AppleScript evaluates by getting the reference's value.

For example, the term word 1 of text body of front document in the following statement is a reference to an object. It identifies the object to which the Copy command is sent. The statement copies the returned value, the first word of the front document, to the variable myWord .

tell application "AppleWorks"
    copy word 1 of text body of front document to myWord
end tell

On the other hand, the term (word 1 of text body of front document) in the following example is a reference expression:

tell application "AppleWorks"
    repeat (word 1 of text body of front document) times
        display dialog "Hello"
    end repeat
end tell

When AppleScript executes this compound Tell statement, it gets the value of the reference word 1 of text body of front document--a string--and then coerces it to an integer, if possible. If the word can't be coerced to an integer, AppleScript reports an error. For information about the Repeat statement, refer to Control Statements For information about coercions, refer to Coercing Values.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)